//
//  WBTabBarController.swift
//  0829-Weibo
//
//  Created by 毕仲阳 on 16/8/29.
//  Copyright © 2016年 mycompany. All rights reserved.
//

import UIKit

class WBTabBarController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        loadChildControllers()
        // Do any additional setup after loading the view.
        let tabbar = WBTabBar()
        //设置tabbar图片渲染颜色 1
        //WBTabBar.appearance().tintColor = UIColor.orange
        //定义一个闭包
        let closure = {[weak self] in
            print("撰写按钮被点击，请弹出菜单\(self)")
            let v = WBComposeView()
//            let window = UIApplication.shared.keyWindow
//            window?.addSubview(v)
            v.show(target: self!)
        }
        tabbar.composeButtonClosure = closure
        self.setValue(tabbar, forKey: "tabBar")
    }

    
    private func addChildViewController(vc:UIViewController,imgName:String,title:String) {
        vc.title = title
        //默认图标
        vc.tabBarItem.image = UIImage(named: imgName)?.withRenderingMode(UIImageRenderingMode.alwaysOriginal)
        
        //选中图标
        vc.tabBarItem.selectedImage = UIImage(named: "\(imgName)_selected")?.withRenderingMode(UIImageRenderingMode.alwaysOriginal)
        //设置选中字体颜色
        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orange], for: UIControlState.selected)
        //vc.tabBarItem.badgeColor = UIColor.purple
        let navController = WBNavigationController(rootViewController: vc)
        
        addChildViewController(navController)
        
    }

   func loadChildControllers()
   {
    addChildViewController(vc: WBHomeController(), imgName:"tabbar_home" , title: "首页")
    addChildViewController(vc: WBMessageController(), imgName:"tabbar_message_center" , title: "消息")
    addChildViewController(vc: WBDiscoverController(), imgName:"tabbar_discover" , title: "发现")
    addChildViewController(vc: WBProfileController(), imgName:"tabbar_profile" , title: "我")
    
   }
}
